#include "buffer.h"

int block_write(int dev, long * pos, char * buf, int count)
{
        int block = *pos / BLOCK_SIZE;
        int offset = *pos % BLOCK_SIZE;
        int chars;
        int written = 0;
        struct buffer_head * bh;
        register char * p;

        while (count>0) {
                bh = bread(dev,block);
                if (!bh)
                        return written?written:-EIO;
                chars = (count<BLOCK_SIZE) ? count : BLOCK_SIZE;
                p = offset + bh->b_data;
                offset = 0;
                block++;
                *pos += chars;
                written += chars;
                count -= chars;
                while (chars-->0)
                        *(p++) = get_fs_byte(buf++);
                bh->b_dirt = 1;
                brelse(bh);
        }
        return written;
}


void ll_rw_block(int rw, struct buffer_head * bh)
{
	rw_hd(rw, bh);
	bh->b_uptodate = 1;
}

